package com.skin;

import android.app.Activity;
import android.app.Application;
import android.view.View;

import com.skin.bean.SkinInfo;
import com.skin.callback.IResourceLoaderCallback;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenxunlin01 on 2017/1/20.
 */

public class SkinManager implements ISkinManager, IResourceLoaderCallback {

    //资源加载器工厂
    private ResourceLoaderFactory resourceLoaderFactory;

    //资源管理器
    private IResourceManager resourceManager;

    private Application context;

    private List<Activity> activityList = new ArrayList<>();

    @Override
    public void init(Application context) {
        this.context = context;
        //初始化工具类
        resourceLoaderFactory = new ResourceLoaderFactory(context);
        //注册属性解析器

        //设置默认的资源管理器

    }

    @Override
    public void registerActivity(Activity activity) {
        if (!activityList.contains(activity)) {
            activityList.add(activity);
        }
    }

    @Override
    public void unRegisterActivity(Activity activity) {
        activityList.remove(activity);
    }

    @Override
    public void switchSkin(SkinInfo skinfo) {
        //切换资源管理器
        IResourceLoader resourceLoader = resourceLoaderFactory.createResourceLoader(skinfo);
        resourceLoader.loaderResource(skinfo, this);
    }

    @Override
    public void skinPeeler(View view) {

    }

    @Override
    public void skinPeerler(Activity activity) {

    }

    @Override
    public void start() {

    }

    @Override
    public void complete(IResourceManager resourceManager) {
        this.resourceManager = resourceManager;
        //通知刷新页面
    }

    @Override
    public void error() {

    }
}
